﻿using G.Service.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace G.Service.BLL
{
    public static class APPTestProjectBLL
    {
        public static Result AddAPPTestProject(int userId, string projectName, string projectConfig)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                return new Result() { Msg = "项目名称不能为空" };
            }
            APPTestProjectData data = new APPTestProjectData();
            if (data.GetAPITestProject(userId, projectName) != null)
                return new Result() { Msg = "已存在该名字的项目" };
            data.AddAPPTestProject(userId, projectName, projectConfig);
            return new Result() { IsOK = true };
        }

        public static Result UpdateProjectConfig(int userId, string projectName, string projectConfig)
        {
                if (string.IsNullOrEmpty(projectName))
                {
                    return new Result() { Msg = "项目名称不能为空" };
                }
                APPTestProjectData data = new APPTestProjectData();
                var temp = data.GetAPITestProject(userId, projectName);
                if (temp == null)
                {
                    data.AddAPPTestProject(userId, projectName, projectConfig);
                }
                else
                {
                    temp.ProjectConfig = projectConfig;
                }
                data.SaveChanges();
                return new Result() { IsOK = true };
        }

        public static Result<APITestProject[]> GetAllAPITestProjectsByUserId(int userId)
        {
            APPTestProjectData data = new APPTestProjectData();
            return new Result<APITestProject[]>() { IsOK = true, ResponseData = data.GetAllAPITestProjectsByUserId(userId) };
        }

    }
}
